export const DefaultTemplate = {
    panels: [{
        "index": 0,
        "name": 1,
        "height": 297,
        "width": 210,
        "paperHeader": 49.5,
        "paperFooter": 780.0000000000001,
        "printElements": [],
        "paperNumberLeft": 565.5,
        "paperNumberTop": 573,
        "paperNumberContinue": true,
        "paperNumberDisabled": false,
        "watermarkOptions": {
            "content": "DMS",
            "rotate": 25,
            "timestamp": true,
            "format": "YYYY-MM-DD HH:mm",
            "fillStyle": "#cccccc"
        },
        "panelLayoutOptions": {}
    }]
}

export const PageSizeList = [
    {
        "name": 'A4',
        "height": 297,
        "width": 210,
    },
    {
        "name": 'A5',
        "height": 210,
        "width": 147.6,
    }
]

export const FormData = {
    Name: '汪析字',
    Age: '18',
    BirthDate: '1990-01-01',
    Picture: '',
    ExpList: [
        {
            Company: '海铭德(岳阳)信息科技有限公司',
            BeginDate: '1990-01-01',
        },
        {
            Company: '深圳海铭德信息科技有限公司',
            BeginDate: '1990-01-01',
        },
        {
            Company: '腾讯控股有限公司',
            BeginDate: '1990-01-01',
        },
    ]
}

export const SimpleFormData = [{
    name: 'Name',
    text: '姓名',
    type: 'text'
}, {
    name: 'Age',
    text: '年龄',
    type: 'text'
}, {
    name: 'BirthDate',
    text: '出生日期',
    type: 'text'
},{
    name: 'Picture',
    text: '照片',
    type: 'image'
}, {
    name: 'ExpList',
    text: '工作经历',
    type: 'table',
    children: [
        {
            name: 'Company',
            text: '公司',
            type: 'text'
        }, {
            name: 'BeginDate',
            text: '起止时间',
            type: 'text'
        }
    ]
}]

export const CreateSimpleFormProvider = function (hiprint, elements) {
    const elementTypes = [];

    for (let i = 0; i < elements.length; i++) {
        const element = elements[i];
        if (element.type !== 'table') {
            const option = {
                width: element.width,
                height: element.height,
                testData: element.text,
            }
            if(element.type === 'image') {
                option.width = 91.5;
                option.height = 117;

                elementTypes.push({
                    tid: `FormModule.${element.name}`,
                    type: element.type,
                    title: element.text,
                    options: {
                        field: element.name,
                        src: '/image/20241031084408.png',
                        height: option.height,
                        width: option.width,
                        fit: "",
                        widthHeightSync: false,
                        coordinateSync: false,
                    }
                })
            } else if(element.type === 'text') {
                option.width = (element.text.length * 18);
                option.width = (element.text.length * 18);
                option.testData = element.text;

                elementTypes.push({
                    tid: `FormModule.${element.name}`,
                    title: element.text,
                    data: element.text,
                    type: element.type,
                    options: {
                        testData: option.testData,
                        height: option.height,
                        fontSize: 9.75,
                        field: element.name,
                        fontWeight: "500",
                        textAlign: "left",
                        hideTitle: true,
                        width: option.width,
                        color: '#000000'
                    }
                })
            }
        } else if (element.type === 'table' && element.children) {
            const fields = element.children.map(x => {
                return {
                    title: x.text,
                    align: 'center',
                    field: x.name,
                }
            });
            console.log('fields', fields)
            elementTypes.push({
                tid: `FormModule.${element.name}`,
                title: element.text,
                type: 'table',
                options: {
                    field: element.name,
                    tableHeaderRepeat: 'first',
                    tableFooterRepeat: 'last',
                    fields: fields,
                },
                editable: true,
                columnDisplayEditable: true,//列显示是否能编辑
                columnDisplayIndexEditable: true,//列顺序显示是否能编辑
                columnTitleEditable: true,//列标题是否能编辑
                columnResizable: true, //列宽是否能调整
                columnAlignEditable: true,//列对齐是否调整
                isEnableEditField: true, //编辑字段
                isEnableContextMenu: true, //开启右键菜单 默认true
                isEnableInsertRow: true, //插入行
                isEnableDeleteRow: true, //删除行
                isEnableInsertColumn: true, //插入列
                isEnableDeleteColumn: true, //删除列
                isEnableMergeCell: true, //合并单元格
                columns: [fields],
                rowsColumnsMerge: function (data, col, index) {
                    return [1, 1]
                },
            })
        }
    }
    const addElementTypes = function (context) {
        context.removePrintElementTypes("FormModule");
        context.addPrintElementTypes(
            "FormModule",
            [
                new hiprint.PrintElementTypeGroup("表单字段", elementTypes)
            ]);
    }
    return {
        addElementTypes
    }
}